package com.crimsec.utils.snmp.web.rest;

import com.crimsec.utils.snmp.model.Event;
import com.crimsec.utils.snmp.service.EventService;
import java.net.URI;
import java.util.List;
import javax.ejb.EJB;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import static javax.ws.rs.core.MediaType.*;
import javax.ws.rs.core.Response;
import org.apache.log4j.Logger;

@Path("event")
public class EventResource {

    private static Logger log = Logger.getLogger("jsnmp.web.event");
    //
    @EJB
    EventService eventService;
    //

    public EventResource() {
    }

    @POST
    @Consumes(APPLICATION_XML)
    @Produces(APPLICATION_XML)
    public Response insert(Event e) {
        log.debug("got post-event-request, with param:" + e);
        eventService.insert(e);
        return Response.created(URI.create("/event/" + e.getId())).build();
    }

    @GET
    @Path("count")
    @Produces(APPLICATION_XML)
    public String getEventsCount() {
        log.debug("got get-events-countrequest");
        return "<event-count>" + eventService.getCount() + "</event-count>";
    }

    @GET
    @Path("{id}")
    @Produces(APPLICATION_XML)
    public Event get(@PathParam("id") long id) {
        log.debug("got get-event-request with id=" + id);
        return eventService.get(id);
    }

    @GET
    @Produces(APPLICATION_XML)
    public List<Event> getEvents(/*TODO: использовать Criteria 
             * API для возврата списка частями*/) {
        log.debug("got get-event-list-request");
        return eventService.getEventList();
    }
}
